﻿
namespace SwtorCalculator {
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for PotionPanel.xaml
    /// </summary>
    public partial class PotionPanel : UserControl {
        /// <summary>
        /// PotionPanel no-arg constructor
        /// </summary>
        public PotionPanel() {
            InitializeComponent();
            if( Character.Stat != null && Character.Stat.Buffs != null ) {
                setClassBuffs();
                setPersonalHidden();
            }
        }

        private void getFlaskChecked( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasReflexStim = ( bool )radReflex.IsChecked ? true : false;
            Character.Stat.Buffs.HasSkillStim = ( bool )radSkill.IsChecked ? true : false;
            Character.Stat.Buffs.HasMightStim = ( bool )radMight.IsChecked ? true : false;
            Character.Stat.Buffs.HasResolveStim = ( bool )radResolve.IsChecked ? true : false;
            Character.Stat.Buffs.HasFortStim = ( bool )radFortitude.IsChecked ? true : false;
            Character.Stat.Buffs.HasCommandStim = ( bool )radCommand.IsChecked ? true : false;
        }

        private void getPotionChecked( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasBattleAttack = false;
            Character.Stat.Buffs.HasBattleEfficacy = false;
            Character.Stat.Buffs.HasBattleCritical = false;
            Character.Stat.Buffs.HasBattleForce = false;
            Character.Stat.Buffs.HasBattleTech = false;
            Character.Stat.Buffs.HasBattleTriage = false;
            Character.Stat.Buffs.HasBattleAbsorb = false;
            
            if( ( bool )radAttack.IsChecked ) {
                chkAttackAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleAttack = true;
            }
            else {
                chkAttackAve.IsChecked = false;
                chkAttackAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleAttackAve = false;
            }

            if( ( bool )radEfficacy.IsChecked ) {
                chkEfficacyAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleEfficacy = true;
            }
            else {
                chkEfficacyAve.IsChecked = false;
                chkEfficacyAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleEfficacyAve = false;
            }

            if( ( bool )radCritical.IsChecked ) {
                chkCriticalAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleCritical = true;
            }
            else {
                chkCriticalAve.IsChecked = false;
                chkCriticalAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleCriticalAve = false;
            }

            if( ( bool )radForce.IsChecked ) {
                chkForceAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleForce = true;
            }
            else {
                chkForceAve.IsChecked = false;
                chkForceAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleForceAve = false;
            }

            if( ( bool )radTriage.IsChecked ) {
                chkTriageAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleTriage = true;
            }
            else {
                chkTriageAve.IsChecked = false;
                chkTriageAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleTriageAve = false;
            }

            if( ( bool )radAbsorb.IsChecked ) {
                chkAbsorbAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleAbsorb = false;
            }
            else {
                chkAbsorbAve.IsChecked = false;
                chkAbsorbAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleAbsorbAve = false;
            }

            if( ( bool )radTech.IsChecked ) {
                chkTechAve.IsEnabled = true;
                Character.Stat.Buffs.HasBattleTech = true;
            }
            else {
                chkTechAve.IsChecked = false;
                chkTechAve.IsEnabled = false;
                Character.Stat.Buffs.UseBattleTechAve = false;
            }
        } 

        private void chkAttackAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleAttackAve = ( bool )chkAttackAve.IsChecked ? true : false;
        }

        private void chkEfficacyAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleEfficacyAve = ( bool )chkEfficacyAve.IsChecked ? true : false;
        }

        private void chkCriticalAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleCriticalAve = ( bool )chkCriticalAve.IsChecked ? true : false;
        }

        private void chkForceAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleForceAve = ( bool )chkForceAve.IsChecked ? true : false;
        }

        private void chkTriageAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleTriageAve = ( bool )chkTriageAve.IsChecked ? true : false;
        }

        private void chkAbsorbAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleAbsorbAve = ( bool )chkAbsorbAve.IsChecked ? true : false;
        }

        private void chkTechAve_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.UseBattleTechAve = ( bool )chkTechAve.IsChecked ? true : false;
        }

        private void chkUnearthPower_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasUnearthedPower = ( bool )chkUnearthPower.IsChecked ? true : false;
        }

        private void chkUnearthMight_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasUnearthedMight = ( bool )chkUnearthMight.IsChecked ? true : false;
        }

        private void chkCritSerum_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasCriticalSerum = ( bool )chkCritSerum.IsChecked ? true : false;
        }

        private void chkFortSerum_Click( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasFortifiedSerum = ( bool )chkFortSerum.IsChecked ? true : false;
        }

        private void setClassBuffs() {
            if( Character.IsRepublic ) {
                chkUnearthPower.Content = "Force Valor";
                chkUnearthPower.ToolTip = "Force Valor\n" + Character.Stat.Buffs.UnearthedPowerText;
                chkUnearthMight.Content = "Force Might";
                chkUnearthMight.ToolTip = "Force Might\n" + Character.Stat.Buffs.UnearthedMightText;
                chkCritSerum.Content = "Lucky Shots";
                chkCritSerum.ToolTip = "Lucky Shots\n" + Character.Stat.Buffs.CriticalSerumText;
                chkFortSerum.Content = "Fortification";
                chkFortSerum.ToolTip = "Fortification\n" + Character.Stat.Buffs.FortifiedSerumText;
            }
            else {
                chkUnearthPower.Content = "Mark of Power";
                chkUnearthPower.ToolTip = "Mark of Power\n" + Character.Stat.Buffs.UnearthedPowerText;
                chkUnearthMight.Content = "Unnatural Might";
                chkUnearthMight.ToolTip = "Unnatural Might\n" + Character.Stat.Buffs.UnearthedMightText;
                chkCritSerum.Content = "Coordination";
                chkCritSerum.ToolTip = "Coordination\n" + Character.Stat.Buffs.CriticalSerumText;
                chkFortSerum.Content = "Hunter's Boon";
                chkFortSerum.ToolTip = "Hunter's Boon\n" + Character.Stat.Buffs.FortifiedSerumText;
            }
        }   

        private void setPersonalHidden() {
            uncheckPersonal();
            setPersonalBuffs();

            radDmgForm.Visibility =
                    Character.ClassName.Equals( "Jedi Knight" ) || Character.ClassName.Equals( "Sith Warrior" ) ?
                    Visibility.Visible : Visibility.Collapsed;
            radTankForm.Visibility =
                    Character.ClassName.Equals( "Jedi Knight" ) || Character.ClassName.Equals( "Sith Warrior" ) ?
                    Visibility.Visible : Visibility.Collapsed;
            radBalanceForm.Visibility =
                    Character.ClassName.Equals( "Jedi Knight" ) || Character.ClassName.Equals( "Sith Warrior" ) ?
                    Visibility.Visible : Visibility.Collapsed;

            radTalentForm.Visibility =
                    Character.AdvanceClass.Equals( "Sentinel" ) || Character.AdvanceClass.Equals( "Marauder" ) ?
                    Visibility.Visible : Visibility.Collapsed;

            radDmgCharge.Visibility =
                    Character.ClassName.Equals( "Sith Inquisitor" ) || Character.ClassName.Equals( "Jedi Consular" ) ?
                    Visibility.Visible : Visibility.Collapsed;
            radTankCharge.Visibility =
                    Character.ClassName.Equals( "Sith Inquisitor" ) || Character.ClassName.Equals( "Jedi Consular" ) ?
                    Visibility.Visible : Visibility.Collapsed;

            radTalentCharge.Visibility = 
                    Character.AdvanceClass.Equals( "Shadow" ) || Character.AdvanceClass.Equals( "Assassin" ) ?
                    Visibility.Visible : Visibility.Collapsed;

            radArPenCell.Visibility =
                    Character.ClassName.Equals( "Bounty Hunter" ) || Character.ClassName.Equals( "Trooper" ) ?
                    Visibility.Visible : Visibility.Collapsed;
            radHealCell.Visibility =
                    Character.ClassName.Equals( "Bounty Hunter" ) || Character.ClassName.Equals( "Trooper" ) ?
                    Visibility.Visible : Visibility.Collapsed;
            radTankCell.Visibility =
                    Character.ClassName.Equals( "Bounty Hunter" ) || Character.ClassName.Equals( "Trooper" ) ?
                    Visibility.Visible : Visibility.Collapsed;
            radDmgCell.Visibility =
                    Character.ClassName.Equals( "Bounty Hunter" ) || Character.ClassName.Equals( "Trooper" ) ?
                    Visibility.Visible : Visibility.Collapsed;

            setGridLayout();
        }

        private void setPersonalBuffs() {
            radDmgForm.Content = "Juyo Form";
            radDmgForm.ToolTip = "Juyo Form\n" + Character.Stat.Buffs.DamageFormText;
            radTankForm.Content = "Soresu Form";
            radTankForm.ToolTip = "Soresu Form\n" + Character.Stat.Buffs.TankFormText;
            radBalanceForm.Content = "Shii-Cho Form";
            radBalanceForm.ToolTip = "Shii-Cho Form\n" + Character.Stat.Buffs.BalanceFormText;
            radTalentForm.Content = "Ataru Form";
            radTalentForm.ToolTip = "Ataru Form\n" + Character.Stat.Buffs.TalentedFormText;
            
            if( Character.IsRepublic ) {
                radDmgCharge.Content = "Force Technique";
                radDmgCharge.ToolTip = "Force Technique\n" + Character.Stat.Buffs.DamageChargeText;
                radTankCharge.Content = "Combat Technique";
                radTankCharge.ToolTip = "Combat Technique\n" + Character.Stat.Buffs.TankChargeText;
                radTalentCharge.Content = "Shadow Technique";
                radTalentCharge.ToolTip = "Shadow Technique\n" + Character.Stat.Buffs.TalentedChargeText;
                radArPenCell.Content = "Armor Piercing Cell";
                radArPenCell.ToolTip = "Armor Piercing Cell\n" + Character.Stat.Buffs.ArPenCellText;
                radHealCell.Content = "Kolto Cell";
                radHealCell.ToolTip = "Kolto Cell\n" + Character.Stat.Buffs.HealCellText;
                radTankCell.Content = "Ion Cell";
                radTankCell.ToolTip = "Ion Cell\n" + Character.Stat.Buffs.TankCellText;
                radDmgCell.Content = "Plasma Cell";
                radDmgCell.ToolTip = "Plasma Cell\n" + Character.Stat.Buffs.DamageCellText;
            }
            else {
                radDmgCharge.Content = "Lightning Charge";
                radDmgCharge.ToolTip = "Lightning Charge\n" + Character.Stat.Buffs.DamageChargeText;
                radTankCharge.Content = "Dark Charge";
                radTankCharge.ToolTip = "Dark Charge\n" + Character.Stat.Buffs.TankChargeText;
                radTalentCharge.Content = "Surging Charge";
                radTalentCharge.ToolTip = "Surging Charge\n" + Character.Stat.Buffs.TalentedChargeText;
                radArPenCell.Content = "High Velocity Gas Cylinder";
                radArPenCell.ToolTip = "High Velocity Gas Cylinder\n" + Character.Stat.Buffs.ArPenCellText;
                radHealCell.Content = "Kolto Gas Cylinder";
                radHealCell.ToolTip = "Kolto Gas Cylinder\n" + Character.Stat.Buffs.HealCellText;
                radTankCell.Content = "Ion Gas Cylinder";
                radTankCell.ToolTip = "Ion Gas Cylinder\n" + Character.Stat.Buffs.TankCellText;
                radDmgCell.Content = "Combustible Gas Cylinder";
                radDmgCell.ToolTip = "Combustible Gas Cylinder\n" + Character.Stat.Buffs.DamageCellText;
            }
        }

        private void getPersonalChecked( object sender, RoutedEventArgs e ) {
            Character.Stat.Buffs.HasDamageForm = ( bool )radDmgForm.IsChecked ? true : false;
            Character.Stat.Buffs.HasTankForm = ( bool )radTankForm.IsChecked ? true : false;
            Character.Stat.Buffs.HasTalentedForm = ( bool )radTalentForm.IsChecked ? true : false;
            Character.Stat.Buffs.HasBalanceForm = ( bool )radBalanceForm.IsChecked ? true : false;
            Character.Stat.Buffs.HasDamageCell = ( bool )radDmgCell.IsChecked ? true : false;
            Character.Stat.Buffs.HasTankCell = ( bool )radTankCell.IsChecked ? true : false;
            Character.Stat.Buffs.HasHealCell = ( bool )radHealCell.IsChecked ? true : false;
            Character.Stat.Buffs.HasArPenCell = ( bool )radArPenCell.IsChecked ? true : false;
            Character.Stat.Buffs.HasDamageCharge = ( bool )radDmgCharge.IsChecked ? true : false;
            Character.Stat.Buffs.HasTankCharge = ( bool )radTankCharge.IsChecked ? true : false;
            Character.Stat.Buffs.HasTalentedCharge = ( bool )radTalentCharge.IsChecked ? true : false;
        }

        private void uncheckPersonal() {
            // Sigh....
            // " foreach statement cannot operate on variables of type 'System.Windows.Controls.GroupBox'
            // because 'System.Windows.Controls.GroupBox' does not contain a public definition for 'GetEnumerator' "

            radDmgForm.IsChecked = false;
            radTankForm.IsChecked = false;
            radTalentForm.IsChecked = false;
            radBalanceForm.IsChecked = false;
            radDmgCharge.IsChecked = false;
            radTankCharge.IsChecked = false;
            radTalentCharge.IsChecked = false;
            radArPenCell.IsChecked = false;
            radHealCell.IsChecked = false;
            radTankCell.IsChecked = false;
            radDmgCell.IsChecked = false;
        }

        private void setGridLayout() {
            if( Character.ClassName.Equals( "Jedi Knight" ) || Character.ClassName.Equals( "Sith Warrior" ) )
                personalRoot.RowDefinitions.RemoveRange( 3, 4 );

            if( Character.ClassName.Equals( "Sith Inquisitor" ) || Character.ClassName.Equals( "Jedi Consular" ) ) {
                personalRoot.RowDefinitions.RemoveRange( 0, 7 );
                //System.Diagnostics.Debug.WriteLine( "Console : " + personalRoot.RowDefinitions.Count );
            }

            if( Character.ClassName.Equals( "Imperial Agent" ) || Character.ClassName.Equals( "Smuggler" ) )
                personalGroup.Visibility = Visibility.Collapsed;
        }
    }
}
